<?php
    
    $reserve_date = date("Y-m-d H:i.s",time());
    $expire_date = date("Y-m-d H:i.s",time()+86400);
    echo "$reserve_date";
    echo "$expire_date";
    
    //reserve_material($materialID,$reserve_date,$expire_date);
    if(isset($_COOKIE["user"]))
     {


        reserve_material($materialID,$reserve_date,$expire_date);

      }
      else
      {
        echo"<script> alert('Please login.');</script>";
        echo("<script> document.location.href='account.php'</script>");
      }
  //function to verify reservation
  function reserve_material ($materialID,$reserve_date,$expire_date)
  {
    $libraryCardNo = $_GET['libraryCardNo'];
    $libraryNo = $_GET['libraryNo'];
    $materialID = $_GET['materialID'];
    //echo"pwede 2";
    require('db_connection.php');
    //check for book details

    $query6 = "SELECT * FROM tblclient WHERE libraryCardNo like '$libraryCardNo'";
    $result6 = mysql_query($query6);
        while($row=mysql_fetch_array($result6))
        {
          $userID = $row['userID'];
        }
    //$userID = $libraryCardNo;
    $query3 = "INSERT INTO tblcirculation VALUES('$userID','reserved','',$libraryNo,'','','$reserve_date','$expire_date', $materialID)";
    //echo $libraryNo;
    $result3 = mysql_query($query3);
    
    echo"<script> alert('Book reservation successful!');</script>";
    //echo $query3;

 
   mysql_close();
  }
  echo"'<script>document.location.href='index.php'</script>'";
  //echo"'<script>history.back();</script>'";

?>

